<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link href="../../css/bootstrap.min.css" rel="stylesheet">
		<script src="../../js/jquery-3.2.1.min.js"></script>
		<script src="../../js/bootstrap.min.js"></script>
		<script type="text/javascript" src="../../js/jquery-2.1.4.js" ></script>
		<script type="text/javascript" src="../../js/path.js" ></script>
		<style>
			
			#container {
				width: 50%;
				margin-left: 250px;
			}
			#but1{
				width: 150px;
				height: 30px;
				background-color: #bce8f1;
		
				font-family: "arial, helvetica, sans-serif";
				color: #31708f;
				border-radius: inherit;
			}
			#jieguo,#jieguo1,#jieguo2{
				color: red;
			}
		</style>
	</head>

	<body>

		<div class="panel panel-info" id="container" align="center">
			<div class="panel-heading">
				<h1 class="panel-title">添加公司</h1>
			</div>
			<div class="panel-body">
				<div style="padding: 100px 100px 10px;" align="center">
      <div class="input-group">
         <span class="input-group-addon">公司名称</span>
         <input type="text" class="form-control"  name="name" onblur="yzName();">
         <div id="jieguo1"></div>
      </div>
         
        	 <br>
        	 	<div id="jieguo"></div>
        	 	
		</div>
		</div>
		<input type="button" value="添加" id="but1"/>
		</div>
	</body>
		<script>
			var xx = getPath()+"/company";
			
			function yzName(){
				var cardNo = $('input[name="name"]').val();
				if(""==cardNo ||  null == cardNo){
					$('#jieguo1').text("请重新输入...");
					return false;
				}else{
					$('#jieguo1').empty();
					return true;
				}
			}
		/* function yzSalary(){
			var cardNo = $('input[name="salary"]').val();
			var patten = new RegExp(/^\d{1,8}(?:\.\d{1,2})?$/);
			if(patten.test(cardNo)!=true){
			 	$('#jieguo2').text("您输入的数字有误 ，请重新输入..(只能输入两位小数)...");
			 	return false;
			 }else {
			 	$('#jieguo2').empty();
			 	return true;
			 }
			 
		} */
			$('#but1').click(function(){
			  
				 if(yzName()){
				 	 $.ajax({
					 	type:'post',
						url:xx+'/add',
						data:{
							name:$('input[name=name]').val(),
							},
						async:true,
						dataType:'json',
						success:function(jsonData){
							console.log(jsonData.result);
							$("#jieguo").text(jsonData.jieguo);
							if(jsonData.result=='success'){
								window.location.href="company-list.html";
							}
						}
					 })
				 }
			})
			
			
		</script>
	</head>
</html>
